package com.jms.service.impl;

import com.jms.entity.User;
import com.jms.mapper.UserMapper;
import com.jms.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * create by yongli on 2021-06-10 23:12
 */
@Service
public class UserServiceImpl implements IUserService {


    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> selectUser() {
        return userMapper.selectUser();
    }

    /**
     * 测试一个这个cache怎么使用
     *
     * @param id
     * @return CachePut可能会写数据，而Cacheable数据
     */
    @Override
    @Cacheable(cacheNames = "userCache", key = "#root.methodName+'['+#id+']'")
//    @Cacheable(cacheNames = "userCache")
    public User selectById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public List<User> selectByUsername(String username) {
        return userMapper.selectByUsername(username);
    }

    @Override
    public int insertOne(User user) {
        return userMapper.insertOne(user);
    }
}
